package com.logistics.heart.entity.model;

import com.logistics.socket.model.ResponseDeviceData;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class HeartSave {

    private String ip;

    private String connectState;

    private String handleState;

    private Integer battery;

    private BigDecimal x;

    private BigDecimal y;

    private BigDecimal yaw;

    private String stage;

    private BigDecimal forkHeight;

    private String agvName;

    private String moveState;

    private String state;

    private String path;

    private Date createTime;

    public HeartSave(ResponseDeviceData data){
        this.ip = data.getAgvip();
        this.connectState = String.valueOf(data.getConnectstate());
        this.handleState = String.valueOf(data.getHandlestate());
        this.moveState = String.valueOf(data.getMovestate());
        this.createTime = new Date();
        this.agvName = data.getAgvname();
        this.stage = data.getStage() ? "1": "0";
        this.battery = data.getMap().getBattery();
        this.x = data.getMap().getPosx();
        this.y = data.getMap().getPosy();
        this.yaw = data.getMap().getYaw();
        this.path = StringUtils.isNotNull(data.getRunpathdetail()) && StringUtils.isNotNull(data.getRunpathdetail().getPath()) ?
                StringUtils.listToString(data.getRunpathdetail().getPath(), ",") : null;
        this.forkHeight = new BigDecimal(data.getMap().getFork_height());
    }

    public static HeartSave build(ResponseDeviceData data){
        return new HeartSave(data);
    }
}
